import { setDefault, addAdd, updateAdd, getAdd, getRegion, getCashgift, getOrder, getCoin, getFavor } from '../../api/my'
import { getToken, setToken, removeToken, setRoles, getRoles, removeRoles } from '../../utils/auth'
// import logo from '@/assets/img/logo.jpg'
const home = {
  state: {
    adds: [],
		regions: null,
		coin: 0,
		orders: [
			{
				title: "刚刚",
				content: "抓取成功",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg?imageView2/3/w/200/h/100/q/90"
			},
			{
				title: "昨天",
				content: "抓取失败",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg?imageView2/3/w/200/h/100/q/90"
			},
			{
				title: "昨天",
				content: "抓取成功",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/cbd.jpg?imageView2/3/w/200/h/100/q/90"
			}
		],
		favor: [
			{ goods_id: 0, img: '../../static/home/1.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 1, img: '../../static/home/2.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 2, img: '../../static/home/3.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 3, img: '../../static/home/4.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 4, img: '../../static/home/5.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 5, img: '../../static/home/6.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 6, img: '../../static/home/7.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 7, img: '../../static/home/8.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 8, img: '../../static/home/9.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' },
			{ goods_id: 9, img: '../../static/home/10.jpg', name: '可爱公仔', price: '30金币/次', slogan:'热抓中' }
		],
		cashgift: [
			{
				title: "刚刚",
				content: "抓取成功",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg?imageView2/3/w/200/h/100/q/90"
			},
			{
				title: "昨天",
				content: "抓取失败",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg?imageView2/3/w/200/h/100/q/90"
			},
			{
				title: "昨天",
				content: "抓取成功",
				img: "https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/cbd.jpg?imageView2/3/w/200/h/100/q/90"
			}
		],
// 		notices: [],
// 		products_a: [],
// 		products_b: [],
// 		products_c: [],
// 		category: [],
  },

  mutations: {
		SET_ADDRESS(state, adds) {
      state.adds = adds
    },
		SET_REGION(state, regions) {
      state.regions = regions
    },
		SET_COIN(state, coin) {
      state.coin = coin
    },
		SET_ORDER(state, orders) {
      state.orders = orders
    },
		SET_FAVOR(state, favor) {
      state.favor = favor
    },
		SET_CASHGIFT(state, cashgift) {
      state.cashgift = cashgift
    },
    SET_AxiosTimeout: (state, axiosTimeout) => {
      state.axiosTimeout = axiosTimeout
    }
  },

  actions: {
		setDefault({ commit }, param) {
      return new Promise((resolve, reject) => {
        setDefault(param).then(data => {
          let [error, res]  = data;
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		addAdd({ commit }, param) {
      return new Promise((resolve, reject) => {
        addAdd(param).then(data => {
          let [error, res]  = data;
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		updateAdd({ commit }, param) {
      return new Promise((resolve, reject) => {
        updateAdd(param).then(data => {
          let [error, res]  = data;
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getAdd({ commit }) {
      return new Promise((resolve, reject) => {
        getAdd().then(data => {
          let [error, res]  = data;
          commit('SET_ADDRESS', res.data.consignees)
					console.log(JSON.stringify(res.data.consignees))
					console.log(res.data.consignees)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getCoin({ commit }) {
      return new Promise((resolve, reject) => {
        getCoin().then(data => {
          let [error, res]  = data;
          commit('SET_COIN', res.data.amount)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getOrder({ commit }, param) {
      return new Promise((resolve, reject) => {
        getOrder(param).then(data => {
          let [error, res]  = data;
					if(res.data.orders.length>0)
						commit('SET_ORDER', res.data.orders)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getFavor({ commit }, param) {
      return new Promise((resolve, reject) => {
        getFavor(param).then(data => {
          let [error, res]  = data;
					if(res.data.products.length>0)
						commit('SET_FAVOR', res.data.products)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getCashgift({ commit }, param) {
      return new Promise((resolve, reject) => {
        getCashgift(param).then(data => {
          let [error, res]  = data;
					if(res.data.cashgifts.length>0)
						commit('SET_CASHGIFT', res.data.cashgifts)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
		getRegion({ commit }) {
      return new Promise((resolve, reject) => {
        getRegion().then(data => {
          let [error, res]  = data;
          commit('SET_REGION', res.data.regions)
					console.log(JSON.stringify(res.data.regions))
					console.log(res.data.regions)
          resolve(res.data)
        }).catch(error => {
					console.log(error);
          reject(error.data)
        })
      })
    },
  }
}

export default home
